from webutils.layers.managers.redis import RedisManager


def ensure_string(value):
    if hasattr(value, 'decode'):
        return value.decode()
    return str(value)


class BaseManager(RedisManager):
    db = 'default'
    required_context = ['room_id']
    key_prefix = 'nc'
    expire_in = 60 * 60 * 24 * 3

    def get_redis_key(self, *parts):
        lst = [self.key_prefix]
        lst.extend(parts)
        return ':'.join(map(ensure_string, parts))
